import React,{useState,useEffect} from 'react'
import './css/suggestion.css';
import Header from "./Header";


const Suggestion = () => {
    const [data,setData] = useState([]);
    const [options,setOptions] = useState({tab:'all',page:1})
    useEffect(()=>{
        fetch(`https:www.h5fd.xyz:2021/test/suggestion`)
            .then(res=>res.json())
            .then(res=>{
                setData(res)
            });
    },[options])

    const delSugg=(id)=>{
        console.log(id);
        fetch(`https:www.h5fd.xyz:2021/test/delsuggest/${id}`)
        .then(res=>res.text())
        .then(res=>{
            if(res==='success'){
                alert('删除成功');
                window.location.reload();
            }
        })

    }

    return (
        <div className="suggestions">
            <h1 className="title">用户反馈</h1>
            <ul className="suggestion">
            {
                data.map((sugg)=>{
                    console.log(sugg)
                    return <li>
                        <p className="pSugg"><span>id:{sugg.suggestion_id}</span> 
                        <span>{sugg.suggestion_content}</span></p>
                        <button className="delSugg" onClick={()=>{delSugg(sugg.suggestion_id)}}>删除</button>
                        </li>
                })
            }
            </ul>
        </div>
    )
}
export default Suggestion;